<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			<el-form-item label="内容名称" prop="contentName">
				<el-input v-model="form.contentName"></el-input>
			</el-form-item>

			<el-form-item label="价格" prop="contentPrice">
				<el-input v-model="form.contentPrice"></el-input>
			</el-form-item>

			<el-form-item label="描述" prop="contentNdesc">
				<el-input v-model="form.contentNdesc"></el-input>
			</el-form-item>


			<el-form-item label="是否增值服务" label-width="130px">
				<el-input v-model="form.isAdd"></el-input>
			</el-form-item>

			<el-form-item label="状态">
				<el-input v-model="form.status"></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'nursecontentAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					contentName: '',
					contentPrice: '',
					contentNdesc: '',
					isAdd: '',
					status: ''
				},
				rules: {
					contentName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					contentPrice: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					contentNdesc: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
				},
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/nurseContent/getById',
					response => {
						// console.log(11111)
						console.log(response.obj.isAdd)
						this.form.contentId = this.editid;
						this.form.contentName = response.obj.contentName;
						this.form.contentPrice = response.obj.contentPrice;
						this.form.contentNdesc = response.obj.contentNdesc;
						this.form.isAdd = response.obj.isAdd;
						this.form.status = response.obj.status;
					}, {
						contentId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				if (this.editid) {
					axios.post(
						'/nurseContent/update',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				} else {
					axios.post(
						'/nurseContent/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				}
			}
		}
	};
</script>

<style></style>
